package cn.edu.java.io.writer;

import java.io.*;

public class OutputStreamWriterDemo {
    public static void main(String[] args) {
        try (// 创建输出流
             ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
             // 创建OutputStreamWriter对象，指定字符编码为UTF-8
             Writer writer = new OutputStreamWriter(byteArrayOutputStream, "UTF-8")) {

            // 写入字符流
            writer.write("Hello, World!");
            writer.write("\n");
            writer.write("你好，世界！");
            writer.flush();

            System.out.println(byteArrayOutputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

